package com.xc.smart.service.impl;
import java.util.Date;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xc.smart.entity.Blog;
import com.xc.smart.entity.User;
import com.xc.smart.entity.dto.BlogDto;
import com.xc.smart.mapper.BlogMapper;
import com.xc.smart.service.BlogService;
import com.xc.smart.utlis.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author mtl
 * 2021/6/9
 */
@Service
public class BlogServiceImpl implements BlogService {

    @Resource
    BlogMapper blogMapper;


    @Override
    public List<Blog> selectBlogList(Integer page, Integer sort) {
        List<Blog> list = blogMapper.selectList(new QueryWrapper<>());
        return list;
    }

    @Override
    public R InsertBolg(User user, BlogDto dto) {
        Blog blog = new Blog();
        blog.setUserId(user.getId());
        blog.setAuthor(user.getUsername());
        blog.setCreateDate(new Date());
        BeanUtil.copyProperties(dto,blog);
        blogMapper.insert(blog);
        return R.ok();
    }


}
